#include<iostream>
#include<cstring>
using namespace std;
const int N = 2e5 + 10;
int arr[N];
int n;
int fun(int x)
{
	while (x % 10 != 2) {
		x = x + x % 10;
	}
	return x;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		memset(arr, 0, sizeof(arr));
		scanf("%d", &n);
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			scanf("%d", &arr[i]);
			if (arr[i] % 5 == 0) {
				cnt++;
			}
		}
		if (cnt && cnt < n) {
			cout << "NO" << endl;
			continue;
		}
		else if (cnt == n) {
			int ma = 0;
			int mi = 1e9;
			for (int i = 1; i <= n; i++) {
				if (arr[i] % 10 == 5) {
					arr[i] += 5;
				}
				ma = max(ma, arr[i]);
				mi = min(mi, arr[i]);
			}
			cout << (ma == mi ? "YES" : "NO") << endl;
		}
		else {
			for (int i = 1; i <= n; i++) {
				arr[i] = fun(arr[i]);
				arr[i] %= 20;
			}
			bool flag = 0;
			for (int i = 2; i <= n; i++) {
				if (arr[i] != arr[i - 1]) {
					flag = 1;
					break;
				}
			}
			if (flag)cout << "NO" << endl;
			else cout << "YES" << endl;
		}
		
	}
	return 0;
}